Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?
You must be signed in to comment.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
L=$((LINES/2))
function f()
{
for A in $(seq $L); do
for B in $(seq $L); do
[ $A -lt $B ] && C=' ' || C=x
echo -n "$C "
done
echo
done
}
X=$(f | tac; f)
paste <(echo "$X") <(echo "$X" | rev) | sed 's/\t //'
The function f draws the bottom-left quadrant. Then I use tac and rev to reflect my way to the others. It compresses down to:L=$((LINES/2));f(){ for A in $(seq $L);do for B in $(seq $L);do [ $A -lt $B ]&&C=' '||C=x;echo -n "$C ";done;echo;done };X=$(f|tac;f);paste <(echo "$X") <(echo "$X"|rev)|sed 's/\t //'
That's 183 characters against your 210.S=$((LINES*2-3))
L=$(printf "x%${S}sx" "")
function g()
{
for A in $(seq $((LINES/2))); do
echo "$L"
L=$(echo "$L" | sed 's/ \( \+\)/ x\1x /')
done
}
g | tac
g
Compressed: 159 characters:S=$((LINES*2-3));L=$(printf "x%${S}sx" "");function g(){ for A in $(seq $((LINES/2))); do echo "$L";L=$(echo "$L" | sed 's/ \( \+\)/ x\1x /');done };g|tac;g
a=$(b=$(($LINES/2-1));f() { for c in $(seq $b); do for i in $(seq $c);do echo x;done|xargs echo;done };paste <(f) <(f|tac|tr 'x' '-') <(f|tac|tr 'x' '-') <(f)|tr '\t' ' ');(cat <<<"$a"|tac;cat <<<"$a")|tr '-' ' '|sed 's/x \| x/+/g'
but, probably being too long, uploaded and copied back from web behaved distorted. Probes with sed 's/^\|$/x/g' in combination with variable string length failed. In command simile toecho {1..10..2}
replacing '10' with variable i.e. $b is not possible, so archaic seq behaves better this way. @flatcap: Your "compressed: 159 characters long" command doesn't work for me (distorted output), but this another one "183 characters long" is fine.... | sed 's/ \( \+\)/ x\1x /'
sed space single-quote s slash space space space space backslash open-bracket space backslash plus backslash close-bracket slash space x backslash 1 x space slash single-quote My next command will be something to transliterate shell-commands into English. Try1: https://gist.github.com/flatcap/7e44ac26e150cd10511b Try2: https://gist.github.com/flatcap/d475cd45bcc5a5f126b7<(f)|tr '\t' ' ')
to<(f)|tr -d '\t')
Then remove the final sed:|sed 's/x \| x/+/g'
Leaving:a=$(b=$(($LINES/2-1));f() { for c in $(seq $b); do for i in $(seq $c);do echo x;done|xargs echo;done };paste <(f) <(f|tac|tr 'x' '-') <(f|tac|tr 'x' '-') <(f)|tr -d '\t');(cat <<<"$a"|tac;cat <<<"$a")|tr '-' ' '